import plotly.express as px
import requests
url="https://api.github.com/search/repositories"
url+="?q=language:python+sort:stars+stars:>10000"

headers={"Accept":"application/vnd.github.v3+json"}

r=requests.get(url,headers=headers)

print(f"Status code:{r.status_code}")
responses_dict=r.json()
print(f"total repositories:{responses_dict["total_count"]}")
print(f"Complete results:{not responses_dict['incomplete_results']}")

repo_dicts=responses_dict["items"]
repo_links,stars,hover_texts=[],[],[]#新建三个列表，一个表示仓库名称，一个表示收藏数量，一个表示悬停文本。
for repo_dicts in repo_dicts:
    repo_name=repo_dicts["name"]
    repo_url=repo_dicts["html_url"]
    repo_link=f"<a href='{repo_url}'>{repo_name}</a>"
    repo_links.append(repo_link)
    owner=repo_dicts["owner"]["login"]
    description=repo_dicts["description"]
    hover_text=f"{owner}<br />{description}"
    hover_texts.append(hover_text)

    stars.append(repo_dicts["stargazers_count"])

title ="Most_Starred Python Projects on Github"
labels={"x":"Repository","y":"Stars"}
fig=px.bar(x=repo_links,y=stars,title=title,labels=labels,hover_name=hover_texts)
fig.update_layout(title_font_size=28,xaxis_title_font_size=20,yaxis_title_font_size=20)
fig.update_traces(marker_color="SteelBlue",marker_opacity=0.6)#用来更新图像呈现的数据，color表颜色，opacity表透明度。
fig.show()